Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLD: Add CMake build using scikit-build-core #242

Merged
merged 44 commits into from
Oct 25, 2024

Conversation

DWesl
Copy link
Contributor

@DWesl DWesl commented Jun 13, 2024

Builds on pyproject.toml added in #241.

DWesl added 18 commits May 23, 2024 16:10
I think I got every key from setup.py.
The main difference is if the READTHEDOCS environment variable is set: I don't know how to change the dependencies based on that.

On the other hand, given 3.8 is close to or past EOL, I suspect 3.3 is relatively uncommon, and the RTD install, without the unneeded bits, could be accomplished with pip install --no-deps.
…tes.

numpy.distutils recommends setuptools<60, but that breaks pyproject.toml
configuration.  I like this way better.  Still needs setup.py for the
fortran module and for the Cheyenne configuration.
setuptools<60 just gets confused, and has no idea what the project name is.
I just inverted that requirement: not sure if setuptools needs to be more recent still.
Works decently as a standalone builder/installer.
Need to work on packaging for python.
Scikit-build-core says it's a good option.
I should delete setup.py before too much longer, shouldn't I.
Pretty sure none of them are designed to be used that way.
Also it kept CMake from trying to execute them with sh.
Can't test locally.  Debating testing in my repo or draft PR.
It's not working, and I'd like to know why.
Only use my versions when skbuild isn't around.
It's not working, and it doesn't look easy to get working on Mac.
Everything should be working now, so let's check.
Requirements list on RTD is much shorter than elsewhere,
so do not install the extra packages on RTD.

The last part of setup.py left is the Cheyenne configuration.
@kafitzgerald
Copy link
Collaborator

Thanks so much for your work here! I just noticed this and your prior PR.

Admittedly, the maintenance on this package has been a struggle and difficult to prioritize.

I'll try to take a look at these shortly.

@kafitzgerald
Copy link
Collaborator

I started looking into this, but haven't been able to get it to build without error. I'm seeing something similar to what's showing up in CI.

I'll try to take a deeper look soon as moving away from distutils is something I'd like to support / make happen.

For some reason this isn't getting written despite every file being .f90 and no file being .f77, so put that in the code.
Let's see if this allows this to build.  I haven't had problems locally with 3.9/1.26
@Plantain
Copy link

Plantain commented Sep 13, 2024

This builds for me, but it fails to actually import at runtime for unclear reasons:

ImportError: /usr/local/lib/python3.12/dist-packages/wrf/_wrffortran.cpython-312-x86_64-linux-gnu.so: undefined symbol: f2pyinitomp_constants_

@DWesl
Copy link
Contributor Author

DWesl commented Sep 13, 2024

This builds for me, but it fails to actually import at runtime for unclear reasons:

ImportError: /usr/local/lib/python3.12/dist-packages/wrf/_wrffortran.cpython-312-x86_64-linux-gnu.so: undefined symbol: f2pyinitomp_constants_

That's a new one. Usually it's complaining about the OpenMP symbols directly. Progress?

On a related note, I think I should look into how to enable OpenMP, since I don't remember doing that.

@Plantain
Copy link

I made a reproduction example in a Docker container.

Dockerfile:

FROM debian:sid
RUN apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade && apt-get -y install curl gfortran build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl git cmake \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
ENV PYENV_ROOT /root/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
RUN curl https://pyenv.run | bash && pyenv install 3.12 && pyenv global 3.12
RUN python3 -m pip install --upgrade setuptools numpy
RUN python3 -m pip install git+https://github.com/DWesl/wrf-python.git@cmake-build
root:~/docker/wrftest# docker build . -t test
[+] Building 0.6s (9/9) FINISHED                                                                                                                                                                                                   docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                                                         0.0s
 => => transferring dockerfile: 632B                                                                                                                                                                                                         0.0s
 => [internal] load metadata for docker.io/library/debian:sid                                                                                                                                                                                0.6s
 => [internal] load .dockerignore                                                                                                                                                                                                            0.0s
 => => transferring context: 2B                                                                                                                                                                                                              0.0s
 => [1/5] FROM docker.io/library/debian:sid@sha256:08cc1a90963e48072614d24e816bb659e62ca9db485151785e12331998766627                                                                                                                          0.0s
 => CACHED [2/5] RUN apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade && apt-get -y install curl gfortran build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl git cmake libncursesw5-dev xz  0.0s
 => CACHED [3/5] RUN curl https://pyenv.run | bash && pyenv install 3.12 && pyenv global 3.12                                                                                                                                                0.0s
 => CACHED [4/5] RUN python3 -m pip install --upgrade setuptools numpy                                                                                                                                                                       0.0s
 => CACHED [5/5] RUN python3 -m pip install git+https://github.com/DWesl/wrf-python.git@cmake-build                                                                                                                                          0.0s
 => exporting to image                                                                                                                                                                                                                       0.0s
 => => exporting layers                                                                                                                                                                                                                      0.0s
 => => writing image sha256:953d34e9016f91f43dc86f06f2b0818a18c8e46c1d4550eda2f112066cca735d                                                                                                                                                 0.0s
 => => naming to docker.io/library/test                                                                                                                                                                                                      0.0s
root:~/docker/wrftest# docker run -ti test
root@181102790b9a:/# python3
Python 3.12.6 (main, Sep 13 2024, 23:33:23) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from wrf import getvar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/.pyenv/versions/3.12.6/lib/python3.12/site-packages/wrf/__init__.py", line 6, in <module>
    from . import api
  File "/root/.pyenv/versions/3.12.6/lib/python3.12/site-packages/wrf/api.py", line 1, in <module>
    from .config import (xarray_enabled, disable_xarray, enable_xarray,
  File "/root/.pyenv/versions/3.12.6/lib/python3.12/site-packages/wrf/config.py", line 6, in <module>
    from ._wrffortran import (fomp_enabled, fomp_set_num_threads,
ImportError: cannot import name 'omp_constants' from 'wrf._wrffortran' (/root/.pyenv/versions/3.12.6/lib/python3.12/site-packages/wrf/_wrffortran.cpython-312-x86_64-linux-gnu.so)
>>>

I think I had it earlier, but deleted it from the link line because I thought the library was fixed-form only, rather than making sure it was available for the link line.
@DWesl
Copy link
Contributor Author

DWesl commented Sep 16, 2024

It appears that numpy.f2py is not generating the .f90 file that would produce a definition for module omp_constants because that module is used and has no functions, only variables. I do not see an obvious manner to override this choice.

Let's see if that's the fix that broke the build
@akrherz
Copy link

akrherz commented Sep 17, 2024

It appears that numpy.f2py is not generating the .f90 file that would produce a definition for module omp_constants because that module is used and has no functions, only variables. I do not see an obvious manner to override this choice.

I think that issue is described here numpy/numpy#19161 , I tried adding a dummy function to trick this, but my fortran foo was not strong enough

akrherz added a commit to regro-cf-autotick-bot/wrf-python-feedstock that referenced this pull request Sep 17, 2024
akrherz added a commit to regro-cf-autotick-bot/wrf-python-feedstock that referenced this pull request Sep 17, 2024
Copy link
Contributor Author

@DWesl DWesl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if these should be matched to the versions in CI as well, but it wouldn't hurt.

CMakeLists.txt Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@kafitzgerald
Copy link
Collaborator

🎉 this is building for me locally now and passing tests.

It looks like there are a few merge conflicts after the last PR was merged. @DWesl is this something you'd like to address or should I go ahead and do it?

I'd like to take a bit more in depth look at the PR itself as well, but hopefully we can get this merged here soon.

Thanks again for your work here!

@DWesl
Copy link
Contributor Author

DWesl commented Oct 15, 2024

I haven't managed to test on Python 3.7, so I'm not sure if I should keep the Python>=3.7 requirement from pyproject.toml or the Python>=3.8 requirement in CMakeLists.txt. Either way, the versions should match.

Nor, for that matter, have I managed to test on Python 3.8, I think due to a different issue.

Copy link
Collaborator

@kafitzgerald kafitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few suggestions here, mostly for consistency.

CMakeLists.txt Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
Comment on lines +47 to +50
# TODO: Figure out the conditionals for running the C Preprocessor on Fortran files
# I think the main thing to be changed is -E -cpp
# Intel is -fpp -save-temps or /fpp on Windows
# or call fpp instead of the fortran compiler to get it to stop after preprocessing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to look into this for Windows at least, but I think that can happen after getting this merged. Maybe along with some testing for Windows.

Don't specify Python version in CMakeLists.txt

Co-authored-by: Katelyn FitzGerald <[email protected]>
@kafitzgerald kafitzgerald merged commit 69fd6a4 into NCAR:develop Oct 25, 2024
13 checks passed
@DWesl DWesl deleted the cmake-build branch October 25, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants